package biz.obake.team.android;

import com.android.billingclient.api.c;
import com.android.billingclient.api.e;
import com.android.billingclient.api.g;
import com.android.billingclient.api.j;
import com.android.billingclient.api.k;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class b implements k {
    private static b e;

    /* renamed from: a  reason: collision with root package name */
    private List<c> f1521a = new ArrayList();

    /* renamed from: b  reason: collision with root package name */
    private d f1522b = d.Disconnected;

    /* renamed from: c  reason: collision with root package name */
    private com.android.billingclient.api.c f1523c;

    /* renamed from: d  reason: collision with root package name */
    private Queue<Runnable> f1524d = new ArrayDeque();

    class a implements e {
        a() {
        }

        public void a() {
            b.this.h(d.Disconnected);
        }

        public void b(g gVar) {
            b bVar;
            d dVar;
            int a2 = gVar.a();
            if (a2 == -1) {
                bVar = b.this;
                dVar = d.Disconnected;
            } else if (a2 != 0) {
                bVar = b.this;
                dVar = d.Error;
            } else {
                b.this.h(d.Connected);
                b.this.f();
                return;
            }
            bVar.h(dVar);
        }
    }

    /* renamed from: biz.obake.team.android.b$b  reason: collision with other inner class name */
    static /* synthetic */ class C0059b {

        /* renamed from: a  reason: collision with root package name */
        static final /* synthetic */ int[] f1526a;

        /* JADX WARNING: Can't wrap try/catch for region: R(8:0|1|2|3|4|5|6|(3:7|8|10)) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0012 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001d */
        /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0028 */
        static {
            /*
                biz.obake.team.android.b$d[] r0 = biz.obake.team.android.b.d.values()
                int r0 = r0.length
                int[] r0 = new int[r0]
                f1526a = r0
                biz.obake.team.android.b$d r1 = biz.obake.team.android.b.d.Disconnected     // Catch:{ NoSuchFieldError -> 0x0012 }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x0012 }
                r2 = 1
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x0012 }
            L_0x0012:
                int[] r0 = f1526a     // Catch:{ NoSuchFieldError -> 0x001d }
                biz.obake.team.android.b$d r1 = biz.obake.team.android.b.d.Error     // Catch:{ NoSuchFieldError -> 0x001d }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x001d }
                r2 = 2
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x001d }
            L_0x001d:
                int[] r0 = f1526a     // Catch:{ NoSuchFieldError -> 0x0028 }
                biz.obake.team.android.b$d r1 = biz.obake.team.android.b.d.Connecting     // Catch:{ NoSuchFieldError -> 0x0028 }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x0028 }
                r2 = 3
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x0028 }
            L_0x0028:
                int[] r0 = f1526a     // Catch:{ NoSuchFieldError -> 0x0033 }
                biz.obake.team.android.b$d r1 = biz.obake.team.android.b.d.Connected     // Catch:{ NoSuchFieldError -> 0x0033 }
                int r1 = r1.ordinal()     // Catch:{ NoSuchFieldError -> 0x0033 }
                r2 = 4
                r0[r1] = r2     // Catch:{ NoSuchFieldError -> 0x0033 }
            L_0x0033:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.android.b.C0059b.<clinit>():void");
        }
    }

    public interface c {
        void a(g gVar, List<j> list);

        void b(d dVar);
    }

    public enum d {
        Disconnected,
        Connecting,
        Connected,
        Error
    }

    public static b d() {
        if (e == null) {
            e = new b();
        }
        return e;
    }

    /* access modifiers changed from: private */
    public void f() {
        while (this.f1524d.size() > 0) {
            int i = C0059b.f1526a[this.f1522b.ordinal()];
            if (i == 1 || i == 2) {
                j();
                return;
            } else if (i == 3) {
                return;
            } else {
                if (i == 4) {
                    this.f1524d.remove().run();
                }
            }
        }
    }

    private void i() {
        c.a f = com.android.billingclient.api.c.f(a.a());
        f.b();
        f.c(this);
        this.f1523c = f.a();
        j();
    }

    private void j() {
        h(d.Connecting);
        this.f1523c.i(new a());
    }

    private void k() {
        com.android.billingclient.api.c cVar = this.f1523c;
        if (cVar != null && cVar.d()) {
            this.f1523c.c();
            this.f1523c = null;
            h(d.Disconnected);
        }
    }

    public void a(g gVar, List<j> list) {
        for (c a2 : this.f1521a) {
            a2.a(gVar, list);
        }
    }

    public com.android.billingclient.api.c c() {
        return this.f1523c;
    }

    public void e(c cVar) {
        boolean z = this.f1521a.size() == 0;
        if (!this.f1521a.contains(cVar)) {
            this.f1521a.add(cVar);
        }
        if (z) {
            i();
        }
    }

    public void g(Runnable runnable) {
        this.f1524d.add(runnable);
        f();
    }

    public void h(d dVar) {
        if (this.f1522b != dVar) {
            this.f1522b = dVar;
            for (c b2 : this.f1521a) {
                b2.b(this.f1522b);
            }
        }
    }

    public void l(c cVar) {
        if (this.f1521a.contains(cVar)) {
            this.f1521a.remove(cVar);
            if (this.f1521a.size() == 0) {
                k();
            }
        }
    }
}
